import {Component, OnInit} from '@angular/core';
import {Router, ActivatedRoute} from "@angular/router";
import {NzMessageService} from 'ng-zorro-antd';
import {TrainingService} from "../../my-service/training.service";

@Component({
  selector: 'app-upload',
  templateUrl: './upload.component.html',
  styleUrls: ['./upload.component.css'],
})
export class UploadComponent implements OnInit {
  trainingID: string;
  userName: string;
  answerID: string;

  constructor(private router: Router,
              private routerInfo: ActivatedRoute,
              private msg: NzMessageService,
              private trainingService: TrainingService) {
  }

  ngOnInit() {
    this.trainingID = this.routerInfo.snapshot.params.ID;
  }

//  去到答题界面
  goAnswer() {
    if (this.userName) {
      this.trainingService.createCardByName(this.trainingID, this.userName).then(res => {
        if (res.status == 1) {
          this.answerID = res.data;
          this.router.navigate(['../answer', {
            ID: this.trainingID,
            answerID: this.answerID
          }], {relativeTo: this.routerInfo})
        }
      })
    } else {
      this.msg.error('请您输入匿名测试的的用户名字，这样方便您查看成绩');
    }
  }

}
